<template>
  <div>
    <router-link to="/" tag="div" class="header-abs" :v-show="showAbs">
      <div class="iconfont header-abs-back">&#xe624;</div>
    </router-link>
    <div class="header-fixed" :style="opacitySty">
      <router-link to='/'>
        <div class="iconfont header-fixed-back">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacitySty: {
        opacity: 0
      }
    }
  },
  methods: {
    handlerScroll () {
      const top = document.documentElement.scrollTop
      if (top > 0) {
        this.showAbs = false
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacitySty = { opacity }
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handlerScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handlerScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-fixed
    overflow hidden
    height $headerHeight
    line-height $headerHeight
    text-align center
    color #ffffff
    background #00bcd4
    font-size .32rem
    position fixed
    top 0
    left 0
    right 0
    z-index 2
    .header-fixed-back
      width .64rem
      text-align center
      font-size .4rem
      color #ffffff
      position absolute
      left 0
      top 0
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    line-height .8rem
    text-align center
    border-radius .4rem
    background rgb(0,0,0,.8)
    .header-abs-back
      color #fff
      font-size .4rem
</style>
